package com.joint.core.dao.impl;

import com.joint.base.dao.impl.BaseEntityDaoImpl;
import com.joint.core.bean.PublicEnum;
import com.joint.core.dao.DictionaryDao;
import com.joint.core.entity.Dictionary;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by dqf on 2015/8/20.
 */
@Repository
public class DictionaryDaoImpl extends BaseEntityDaoImpl<Dictionary, String> implements DictionaryDao{
    @Override
    public List<Dictionary> findByTypeAll(PublicEnum.DictionaryEnm type) {
        String hql = " from "+this.entityClass.getName()+" dic where dic.type= :type and dic.state = 'Enable' ";
        List<Dictionary> list = getSession().createQuery(hql).setParameter("type",type).list();
        return list;
    }

    @Override
    public List<Dictionary> findByType(PublicEnum.DictionaryEnm type, boolean isClosed) {
        String hql = " from "+this.entityClass.getName()+" dic where dic.type= :type and dic.isClosed= :isClosed and dic.state='Enable' ";
        List<Dictionary> list = getSession().createQuery(hql).setParameter("type",type).setParameter("isClosed",isClosed).list();
        return list;
    }

    @Override
    public List<Dictionary> findChildAll(Dictionary dict) {
        String hql = " from "+this.entityClass.getName()+" dic.father= :dict and dic.state='Enable' ";
        List<Dictionary> list = getSession().createQuery(hql).setParameter("dict",dict).list();
        return list;
    }

    @Override
    public List<Dictionary> findChildByState(Dictionary dict, boolean isClosed) {
        String hql = " from "+this.entityClass.getName()+" dic.father= :dict and dic.state='Enable' and dic.isClosed= :isClosed";
        List<Dictionary> list = getSession().createQuery(hql).setParameter("dict",dict).setParameter("isClosed",isClosed).list();
        return list;
    }
}
